package com.demo.task;

import com.demo.ws.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/2/14 0014.
 */
@Component
public class Task {
    @Autowired
    private WebSocketService webSocketService;

    @Scheduled(cron = "*/5 * * * * ?")
    public void test() throws IOException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        System.out.println(sdf.format(date));
        webSocketService.sendMessage(sdf.format(date));
    }
}
